package 程序员面试金典;

import org.junit.Test;

import java.sql.PseudoColumnUsage;

public class 一次替换 {

    public boolean oneEditAway(String first, String second) {
        int len = first.length() - second.length();
        if (len>1 ||len<-1)
            return false;
          int i=0,j=0;
          int sum=0;
          while (i<first.length() && j<second.length()){
              if (first.charAt(i)!=second.charAt(j)){
                  if (sum>0)
                      return false;
                  sum++;
                  if (first.length()>second.length())
                      j--;
                  else if (first.length()<second.length())
                      i--;
              }
               i++;
               j++;
          }
          return true;
    }
    @Test
    public void test(){
        System.out.println(oneEditAway("a", "a"));
    }

}
